import 'package:flutter/material.dart';
import 'package:flutter_uikit/common/app_colors.dart';
import 'package:get/get.dart';
import '../../model/chart/chart_menu_item_model/chart_menu_item_model.dart';
import 'chart_logic.dart';
import 'widget/chart_row_widget.dart';

class ChartPage extends StatefulWidget {
  const ChartPage({Key? key}) : super(key: key);

  @override
  State<ChartPage> createState() => ChartPageState();
}

class ChartPageState extends State<ChartPage> {
  final logic = Get.put(ChartLogic());
  final state = Get.find<ChartLogic>().state;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: AppColors.colorFF282E45,
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(state.title ?? ""),
      ),
      body: ListView.builder(
          shrinkWrap: false, //列表的高度是否根据内容自动设定
          scrollDirection: Axis.vertical, //列表滑动方向
          itemCount: state.menuItemList!.length, //item总个数
          itemBuilder: (BuildContext context, int index) {
            //每个item的布局
            ChartMenuItemModel item = state.menuItemList![index];
            return ChartRowWidget(
              text: item.text,
              svgPath: item.iconPath,
              onTap: () {
                  logic.itemEvent(item);
              },
            );
          }),
    );
  }
}
